﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MxWeiXinPF.Common;
using MxWeiXinPF.BLL;


namespace MxWeiXinPF.Web.admin.wxapp
{
    public partial class wxappverifyDetail : Web.UI.ManagePage
    {

        wxapp_userList auBll = new wxapp_userList();
        public int auid = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
          
            auid = MyCommFun.RequestInt("auid");
            if (auid == 0)
            {

                JscriptMsg("传输参数不正确！", "back");
                return;
            }
            if (!auBll.Exists(auid))
            {
                JscriptMsg("记录不存在或已被删除！", "back");
                return;
            }
            if (!Page.IsPostBack)
            {
                ShowInfo(auid);
            }
            

        }



        #region 赋值操作=================================

        private void ShowInfo(int id)
        {

            hidid.Value = id.ToString();
            DataSet ds = auBll.GetTotModel(id);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];
                //有数据


                lblUserName.Text = MyCommFun.ObjToStr(dr["user_name"]);
                lblStorName.Text = MyCommFun.ObjToStr(dr["storeName"]);
                lblWxappName.Text = MyCommFun.ObjToStr(dr["wxappName"]);
                txtverifyTime.Text = MyCommFun.Obj2DateTime(dr["auvalidDate"], DateTime.Now).ToShortDateString();
                rblStatus.SelectedValue = MyCommFun.ObjToStr(dr["austatus"]);

                string auqrCodeUrl = MyCommFun.ObjToStr(dr["auqrCodeUrl"]);

                if (auqrCodeUrl != "")
                {
                    imgQRPic.ImageUrl = auqrCodeUrl;
                }
                 



            }

        }

        #endregion



        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            int id = MyCommFun.Str2Int(hidid.Value);
            if(id<=0)
            {
                JscriptMsg("id不符合条件", "back");
                return;
            }

            string strErr = "";
            if (MyCommFun.Obj2DateTime(this.txtverifyTime.Text, DateTime.Parse("1990-1-1")) == DateTime.Parse("1990-1-1"))
            {
                strErr += "有效周期不对！";
            }
            

            DataSet ds = auBll.GetTotModel(id);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                Model.wxapp_userList auModel = new Model.wxapp_userList();
                auModel = auBll.GetModel(id);

                auModel.validDate = MyCommFun.Obj2DateTime(this.txtverifyTime.Text, DateTime.Parse("1990-1-1"));
                auModel.status =MyCommFun.Str2Int(rblStatus.SelectedItem.Value);
                auModel.verifyTime = DateTime.Now;

                auModel.verifyPerson = GetAdminInfo().user_name;

              bool ret=  auBll.Update(auModel);

              if (ret)
              {
                  AddAdminLog(MXEnums.ActionEnum.Confirm.ToString(), "操作审核用户购买的小程序成功，主键为" + id); //记录日志
                  JscriptMsg("操作成功！", "wxappverifylist.aspx");
              }
              else
              {
                  AddAdminLog(MXEnums.ActionEnum.Confirm.ToString(), "操作审核用户购买的小程序失败，主键为" + id); //记录日志
                  JscriptMsg("操作成功！", "wxappverifylist.aspx");
              }



            }


        }



    }
}